<?php
defined('JPATH_BASE') or die();

jimport('joomla.filesystem.file'); 
jimport('joomla.filesystem.folder'); 

class JElementNodetype extends JElement
{ 
	
	
	function fetchElement($name, $value, &$node, $control_name)
	{ 	
		$db	=	$this->getDBO();
		
		$query	=	"SELECT type,name FROM #__node_type";
		$db->setQuery($query);
		$options	=	$db->loadObjectList();
		array_unshift($options, JHTML::_('select.option', '0', '- '.JText::_('Select Node').' -', 'type', 'name'));
		ob_start();
		?>
		<script type="text/javascript">
			window.addEvent('domready',function(){
				$('paramstype').addEvent('change',changeStyle);
				changeStyle();
				function changeStyle()
				{
					var now = new Date();		
					var url = 'index.php';		
					var data=Object.toQueryString({option: 'com_yos_news_crawler',task:'jobs.actionCms',style: $('paramstype').value,action: 'changestyle',cms:'drupal'});
					var MyAjax_detail = new Ajax(url, {
						method: 'get',
						data: data,						
						evalScripts: true,
						onRequest: function(){				
						},
						onComplete: function(responseText,responseXML){
							$('term').innerHTML	=	responseText;							
							setTermValue();
						}
					});
					MyAjax_detail.request();
				}
			});
		</script>
			
		<?php
		echo  JHTML::_('select.genericlist', $options, $control_name.'['.$name.']', 'class="inputbox" size="1"', 'type', 'name', $value);
		$str	=	ob_get_contents();
		ob_end_clean();
		return $str;
	}
	function getDBO()
	{
		require(JPATH_COMPONENT_ADMINISTRATOR.DS.'cms'.DS.'drupal'.DS.'cms_config.php');		
		$option_ 	= array(); //prevent problems 
		$option_['driver']   = $d_w_driver;       	// Database driver name
		$option_['host']     = $d_w_host;    		// Database host name
		$option_['user']     = $d_w_user;  	    	// User for database authentication
		$option_['password'] = $d_w_password;  		// Password for database authentication
		$option_['database'] = $d_w_database;  	  	// Database name
		$option_['prefix']   = $d_w_prefix;          // Database prefix (may be empty)
		if (empty($option_['user']) || empty($option_['password']) || empty($option_['database']) || empty($option_['driver']) || empty($option_['host']))
		{
			$config	=	JFactory::getConfig();
			
			$option_['driver']   = $config->getValue('dbtype');       	// Database driver name
			$option_['host']     = $config->getValue('host');    		// Database host name
			$option_['user']     = $config->getValue('user');  	    	// User for database authentication
			$option_['password'] = $config->getValue('password');  		// Password for database authentication
			$option_['database'] = $config->getValue('db');  	  	// Database name
		}
		$db_	= &JDatabase::getInstance( $option_ );
		if (!empty($db_->message)) {
				$this->msg = JText::sprintf($db_->message);
				return false;
			}	
		$this->_dbo=$db_;
		return $this->_dbo;
	}
}
